#include "process.h"
#include <string.h>

#define LENGTH 101
#define charac '#'

void Process()
{
    const char* strm = "\\|/-";
    int a = strlen(strm);
    char bar[LENGTH];
    memset(bar, '\0', sizeof(bar));
    for(int i = 0; i <= 100 ; i++)
    {
        printf("[%-100s][%d%%][%c]\r", bar, i, strm[i % a]);
        bar[i] = charac;
        fflush(stdout);
        usleep(50000);
    }
    printf("\n");
}


void FlushProcess(double cur_total)
{
    const static char* strm = "\\|/-";
    static int index = 0;

    int a = strlen(strm);
    char bar[LENGTH];
    memset(bar, '\0', sizeof(bar));
    int cnt = (int)cur_total;
    for(int i = 0; i < cur_total; i++)
    {
        bar[i] = charac;
    }
    printf("[%-100s][%.1lf%%][%c]\r", bar, cur_total, strm[index++]);
    fflush(stdout);
    index %= a;
}
